package blackjack;

import java.util.ArrayList;
import java.util.Collections;

public class Deck {
    private ArrayList<Card> cards;

    // 构造函数，用于初始化一副包含所有扑克牌（不包含大小王）的牌组
    public Deck() {
        this.cards = new ArrayList<Card>();
        initializeDeck();
    }

    // 初始化一整副牌（仅在构造函数中使用）
    private void initializeDeck() {
        String[] ranks = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace"};
        String[] suits = {"Heart", "Diamond", "Club", "Spade"};
        for (String rank: ranks) {
            for (String suit: suits) {
                Card card = new Card(rank, suit);
                cards.add(card);
            }
        }
    }

    // 获取牌组中剩余的扑克牌数量
    public int getDeckSize() {
        return cards.size();
    }

    // 从牌组中抽取一张扑克牌
    public Card drawCard() {
        if (cards.size() > 0) {
            return cards.remove(cards.size() - 1);
        }
        System.out.println("No more cards in the deck!");
        return null;
    }

    // 洗牌
    public void shuffle() {
        Collections.shuffle(cards);
    }

}
